home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / mcu332 / 332src.arc / CHIPSEL.SA < prev    next >
Text File  |  1990-05-02  |  20KB  |  400 lines

  1.         TTL       M68332 BUSINESS CARD COMPUTER CHIP SELECT INIT
  2.         OPT       P=68332             SETUP FOR 68332 CODE
  3.         OPT       BRS                 SHORT BRANCHES PREFERED
  4.  
  5. ******************************************************************************
  6. *** EXPORTED PORTION OF THE MODULE HEADER                                  ***
  7. *V****************************************************************************
  8. ******************************************************************************
  9. ***                                                                        ***
  10. *** MODULE :       CHIP SELECT INITIALIZATION                              ***
  11. ***                                                                        ***
  12. *** ENVIRONMENT :  68332 Business Card Computer (BCC) Rev. A, B            ***
  13. ***                For M68332PFB Platform Board, Rev. A, B, C              ***
  14. ***                                                                        ***
  15. ***                NOTE:  BCC Rev. A + PFB Rev. A = Old System             ***
  16. ***                       BCC Rev. B + PFB Rev. B = New System             ***
  17. ***                                                                        ***
  18. ***                       PFB Rev. C is jumper selectable to be function-  ***
  19. ***                       ally equivalent to Rev. A or to Rev. B.          ***
  20. ***                                                                        ***
  21. ***                 ---- DO NOT MIX REV. A's WITH REV. B's! ----           ***
  22. ***                 ---- NO STACK USAGE (SUBR'S) ALLOWED!   ----           ***
  23. ***                                                                        ***
  24. *** LANGUAGE :     68332 ASSEMBLY LANGUAGE                                 ***
  25. ***                                                                        ***
  26. *** SUMMARY OF CONTENTS :                                                  ***
  27. ***     Determines BCC type (A or B) and initializes the appropriate chip  ***
  28. ***     selects using the corresponding values from the parameter area.    ***
  29. ***                                                                        ***
  30. *** LINK REQUIREMENTS :                                                    ***
  31. ***   NOTES:                                                               ***
  32. ***     1.  Source equivalent copy of 332Bug parameter area for Motorola   ***
  33. ***         FREEWARE Bulletin Board System (BBS) to produce object         ***
  34. ***         equivalent code.  See REVISION HISTORY below for version nbr.  ***
  35. ***     2.  This source code can be freely used at no cost/obligation,     ***
  36. ***         i.e. it is PUBLIC DOMAIN software.  Please report any errors/  ***
  37. ***         additions to the SYSOP of the Motorola FREEWARE BBS.           ***
  38. ***     3.  Parameters which reference linker symbols (XREF/XDEF) will     ***
  39. ***         not be defined until link time, so the obj. code listed here   ***
  40. ***         will not match the actual EPROM code.                          ***
  41. ***                                                                        ***
  42. ******************************************************************************
  43. *^****************************************************************************
  44. *
  45.          PAGE
  46. *
  47. ******************************************************************************
  48. *** INTERNAL PORTION OF THE MODULE HEADER                                  ***
  49. ******************************************************************************
  50. ***                                                                        ***
  51. ***   REVISION HISTORY (add changes to the top):                           ***
  52. ***                                                                        ***
  53. ***      DATE         AUTHOR               CHANGES                         ***
  54. ***   ----------  ---------------  -------------------------------------   ***
  55. ***    01/17/90   Peter S. Gilmour Initial version port to MS_DOS based    ***
  56. ***                                M68MASM from original source code.      ***
  57. ***                                Compatible with 332Bug version 1.01.    ***
  58. ***    05/02/90   Peter S. Gilmour Compatible with 332Bug version 1.02.    ***
  59. ******************************************************************************
  60. *** XDEFS :                                                                ***
  61.         XDEF    INIT_CS
  62. ***                                                                        ***
  63. *** XREFS :                                                                ***
  64.         XREF    PWR_TTL
  65.         XREF    .RAMMCR
  66.         XREF    .RAMBAR
  67.         XREF    .CSBAR0,.CSBAR1,.CSBAR2,.CSBARBT
  68.         XREF    CSBAR0$
  69. ***                                                                        ***
  70. ***   Local macros:                                                        ***
  71. ***                                                                        ***
  72. SYSTEM   MACRO                         ! SETUP MONITOR SPACE
  73. SECTD    SET       1                   ! DEFINE DATA SECTION
  74. SECTP    SET       14                  ! DEFINE PROGRAM SECTION
  75.          SECTION   SECTP               ! PUT USER INTO PROG. SECTION
  76.          ENDM                          !
  77. *
  78. * Time delay macro
  79. *   - allows bus capacitance to dissipate
  80. *   - at least 3 words must be fetched to guarantee dissipation
  81. *
  82. T_DELAY MACRO
  83.         NOP
  84.         NOP
  85.         NOP
  86.         ENDM
  87.  
  88. ***
  89. ***   Local equates:
  90. ***
  91. OLD_BCC  EQU       0         Code ID for old BCC
  92. NEW_BCC  EQU       1         Code ID for new BCC
  93.  
  94. *
  95. *  For M68332 BCC and PFB.
  96. *
  97. *  NOTE: Unused upper address lines are specified as 1's so ABSOLUTE SHORT
  98. *        addressing (sign extension) can be used.
  99. *
  100. SR_VAL    EQU      $2700               status register initial value.
  101.  
  102. RAM_BASE  EQU      $0                  BCC RAM base address
  103. RAM_SIZE  EQU      $10000              BCC RAM size (bytes)
  104. ROM1_BASE EQU      $60000              BCC EPROM base address
  105. ROM1_SIZE EQU      $20000              BCC EPROM size (bytes)
  106. IRAM_BASE EQU      $40000
  107. FPCP_BASE EQU      $FFFFE800           PFB MC68881/MC6882 base address
  108. *                                      .  (Floating Point Co-Processor)
  109. SIM       EQU      $FFFFFA00           BCC M68332 System Integration Module base addr
  110. RAMCR     EQU      $FFFFFB00           BCC M68332 RAM Control Module base address
  111. AUTO_BASE EQU      $FFFFF800           Autovector base address
  112.  
  113. LOCALRAM  EQU      RAM_BASE            base of local RAM
  114. SYSRAMSZ  EQU      $00004000           size of local RAM (for system use)
  115. LCLRAMMX  EQU      RAM_SIZE            max size of local RAM (for M68332 BCC)
  116. USRRAM    EQU      LOCALRAM+SYSRAMSZ   base of user RAM
  117. USRRAMSZ  EQU      LCLRAMMX-SYSRAMSZ   size of user RAM
  118. RAMSTART  EQU      LOCALRAM            alias for base of local RAM
  119.  
  120. LOCALROM  EQU      ROM1_BASE           base of local ROM (use PC rel refs!)
  121. LCLROMSZ  EQU      $00010000           size of local ROM used by 332Bug
  122. ROMUNPGM  EQU      $FF                 unprogrammed state of a byte of EPROM
  123. FILL.1    EQU      ROMUNPGM            fill value for 1 byte = BYTE
  124. FILL.2    EQU      FILL.1<<8+FILL.1    fill value for 2 bytes= WORD
  125. FILL.4    EQU      FILL.2<<16+FILL.2   fill value for 4 bytes= LONG WORD
  126.  
  127. RAM2_BASE EQU      LOCALRAM+LCLRAMMX   Next RAM base address
  128. ROM2_BASE EQU      ROM1_BASE+ROM1_SIZE Next ROM base address
  129.  
  130. VECTSIZ  EQU       $400                Vector table size
  131. USERLEN  EQU       $1000               user space reserved
  132. MEMINC   EQU       $4000               memory increment for 130's or EVM's
  133. STKLEN   EQU       MEMINC-USERLEN-VECTSIZ-4 size of bug/diag stack + static vars
  134.  
  135. *
  136. * Interrupt levels & vectors
  137. *
  138. ABORTLVL EQU       7                   abort level
  139. ABORTVEC EQU       31                  abort vector
  140. ACFAILVL EQU       7                   AC-Fail level
  141. ACFAILVC EQU       65                  AC-Fail vector
  142. TIMERLVL EQU       6                   timer level: M68332 periodic int. timer
  143. TIMERVEC EQU       66                  timer vector
  144.  
  145. *
  146. *  Setup Base Addresses:
  147. *    1. A31-A24 must= 0  (MC68332 only uses A0-A23; rest are unused!)
  148. *    2. A10-A0  must= 0  (for Base Address Register usage).
  149. *
  150. ADDRMASK EQU       $00FFF800           Address mask (24-bits, A10-A0= 0)
  151. RAM      EQU       RAM_BASE&ADDRMASK   Setup Base Addresses
  152. ROM      EQU       ROM1_BASE&ADDRMASK  Setup Base Addresses
  153. RAM2     EQU       RAM2_BASE&ADDRMASK  Setup Base Addresses
  154. ROM2     EQU       ROM2_BASE&ADDRMASK  Setup Base Addresses
  155. FPCP     EQU       FPCP_BASE&ADDRMASK  Setup Base Addresses
  156. IRAM     EQU       IRAM_BASE&ADDRMASK  Setup Base Addresses
  157. AVEC_7   EQU       AUTO_BASE&ADDRMASK  Setup Base Addresses
  158.  
  159. CSBAR_XX EQU       $0000               Reset (unused) value for CSBARn
  160. CSOR_XX  EQU       $0000               Reset (unused) value for CSORn
  161.  
  162. RAMMCR   EQU       RAMCR+$00           RAM Module Configuration Register
  163. RAMBAR   EQU       RAMCR+$04           RAM Module Base Address/Status Register
  164. SYNCR    EQU       SIM+$04             Clock Synthesizer Control Register
  165. VCO_X    EQU       $4000               VCO Frequency Control Bit X value
  166. SYPCR    EQU       SIM+$20             System Protection Control Register
  167. CSPAR    EQU       SIM+$44             Chip Select Pin Assignment Register
  168. CSBARBT  EQU       SIM+$48             Chip Select Base Boot Register
  169. CSORBT   EQU       SIM+$4A             Chip Select Option Boot Register
  170. CSBAR0   EQU       SIM+$4C             Chip Select 0 Base Register
  171. CSOR0    EQU       SIM+$4E             Chip Select 0 Option Register
  172. CSBAR1   EQU       SIM+$50             Chip Select 1 Base Register
  173. CSOR1    EQU       SIM+$52             Chip Select 1 Option Register
  174. CSBAR2   EQU       SIM+$54             Chip Select 2 Base Register
  175. CSOR2    EQU       SIM+$56             Chip Select 2 Option Register
  176.  
  177. *
  178. * Option Register Equates (CSORBT, CSORn):
  179. *
  180. B2K      EQU       0                   2K    block size
  181. B8K      EQU       1                   8K    block size
  182. B16K     EQU       2                   16K   block size
  183. B64K     EQU       3                   64K   block size
  184. B128K    EQU       4                   128K  block size
  185. B256K    EQU       5                   256K  block size
  186. B512K    EQU       6                   512K  block size
  187. B1M      EQU       7                   1MB   block size
  188. ASYNC    EQU       $0000               Asynchronous mode
  189. SYNC     EQU       $8000               Synchronous  mode
  190. CS_UPPB  EQU       2*$2000             Upper byte
  191. CS_LOWB  EQU       1*$2000             Lower byte
  192. CS_BOTHB EQU       3*$2000             Both  bytes (upper or lower)
  193. CS_R     EQU       1*$800              Read
  194. CS_W     EQU       2*$800              Write
  195. CS_RW    EQU       3*$800              Read or write
  196. CS_AS    EQU       0*$400              Address Strobe (AS*)
  197. CS_DS    EQU       1*$400              Data    Strobe (DS*)
  198. CS_FAST  EQU       14                  Fast     termination DSACK*
  199. CS_EXT   EQU       15                  External termination DSACK*
  200. CS_WAIT  EQU       1*$40               Wait cycles for DSACK*
  201. CS_CSP   EQU       0*$10               CPU  space
  202. CS_USP   EQU       1*$10               User space
  203. CS_SSP   EQU       2*$10               Supervisor space
  204. CS_SUSP  EQU       3*$10               Supervisor/User space
  205. CS_LVL   EQU       1*$2                Interrupt priority level
  206. CS_AVEC  EQU       1                   Autovector enable
  207.  
  208.  
  209. ******************************************************************************
  210. *
  211.         SYSTEM
  212.  
  213. * Start Chip Select Initialization:
  214. *
  215. INIT_CS:
  216.         MOVE.W    #SR_VAL,SR            Ensure status register initialized.
  217.  
  218. * Set up SYSTEM PROTECTION REGISTER:
  219. *
  220.         MOVE.W    #6,SYPCR              Turn off cop, DBF: BERR=16 clocks.
  221.  
  222. * Now let's go to 16.7 MHZ:
  223. *
  224.         OR.W      #VCO_X,SYNCR          X-bit doubles the current speed!
  225.  
  226. * Remap Internal Standby RAM Module per CONFIGURATION PARAMETER values:
  227. *
  228.         MOVE.W    ((.RAMBAR).L,PC),D1   Get RAM Array Base Addr. value (RAMBAR).
  229.         BTST      #0,D1                 .  (Bit 0= RAMDS bit)
  230.    IF  <EQ>  THEN.S                     If RAM Array Disabled Flag = OFF, then
  231.         MOVE.W    ((.RAMMCR).L,PC),D0   .  Get RAM Module Config. Reg. value
  232.         MOVE.W    D0,RAMMCR             .  and put it in the register.
  233.         MOVE.W    D1,RAMBAR             .  Put RAMBAR value into the register.
  234. * NOTE:  RAMBAR can only be written once!
  235.    ENDI
  236.  
  237. * Enable SHOW CYCLES and allow INTERRRUPT ARBITRATION at priority 15:
  238. *
  239.         OR.W      #$020F,SIM            Enable show cycles & external arb. @ 15
  240.         AND.W     #$DFFF,SIM            Clear FRZBM bit= when FREEZE bus moni-
  241. *                                       tor continues to operate as programmed.
  242.  
  243. *
  244. * Set up all Chip Selects as "chip selects" in case user's have connected h/w
  245. * devices.  Otherwise, address lines would be toggling as program runs and
  246. * possibly cause the devices to be enabled!
  247.         MOVE.L    #$FFFFFFFF,CSPAR      All = chip selects, 16-bit port
  248. *                                       .  (unused bits have no effect!)
  249.  
  250. * Set up RAM and CSBOOT CHIP SELECTs to old BCC values:
  251. *
  252.         MOVE.L    ((.CSBAR0).L,PC),CSBAR0
  253.         MOVE.L    ((.CSBAR1).L,PC),CSBAR1
  254.         MOVE.L    ((.CSBARBT).L,PC),CSBARBT
  255.  
  256. * Test for old BBC by enabling its onboard RAM and ROM.
  257. * If RAM found, then
  258. *   assume old BCC with old Platform Board
  259. * else
  260. *   assume new BCC with new Platform Board
  261. * endif
  262. * If board == old_BCC 
  263. *   initialize chip selects for old BCC and old platform board
  264. * else
  265. *   initialize chip selects for new BCC and new platform board
  266. * endif
  267. *
  268. * To find RAM:
  269. *   ($0000) = $5AA5A55A
  270. *   delay to allow bus capacitance to dissipate
  271. *   if ($0000) == $5AA5A55A then
  272. *     ($0000) = $A55A5AA5
  273. *     delay to allow bus capacitance to dissipate
  274. *     if ($0000) == $A55A5AA5 then
  275. *       RAM found
  276. *     endif
  277. *   else
  278. *      ($4000) = $5AA5A55A
  279. *      delay to allow bus capacitance to dissipate
  280. *      if ($4000) == $5AA5A55A then
  281. *        ($4000) = $A55A5AA5
  282. *        delay to allow bus capacitance to dissipate
  283. *        if ($4000) == $A55A5AA5 then
  284. *          RAM found
  285. *        endif
  286. *     endif
  287. *  endif
  288. *
  289.  
  290. * NOTE:  By default at Power Up, CSBOOT responds to any address in the
  291. *        range of $0-$FFFFF (block size= 1 MB) to select the Boot ROM.
  292. *        Since the Boot ROM only uses address lines A0-A16 (128K), it
  293. *        appears replicated thru the memory map at every even ROM size
  294. *        ($20000) boundary as follows:
  295. *           $00000, $20000, $40000, $60000, $80000, $A0000, $C0000, $E0000
  296. *        Thus the power up reset vectors for the SP and PC are fetched from
  297. *        locations $0-7 and the PC is set to the memory range where we will
  298. *        be programming the Boot ROM to appear at via the chip selects.
  299. *        When the programming occurs, there are no addressing "glitches"
  300. *        because we stay at the same locations!
  301.  
  302.         MOVEQ.L   #NEW_BCC,D0
  303.         MOVE.L    #$5AA5A55A,D1           NOTE:  D1 and D2 are inverse patterns!
  304.         MOVE.L    #$A55A5AA5,D2
  305.         SUB.L     A0,A0                   Test loca. = $0000.
  306.  
  307.         MOVE.L    D1,(A0)
  308.         T_DELAY
  309.         IF.L  D1 <EQ> (A0)  THEN.S        If test loca. is good, then
  310.            MOVE.L    D2,(A0)
  311.            T_DELAY
  312.            IF.L  D2 <EQ> (A0)  THEN.S     .  If inverse is good, then
  313.               MOVEQ.L   #OLD_BCC,D0       .    Got RAM, so must be old BCC!
  314.            ENDI
  315.         ELSE.S                            else maybe just 1 bad loca.
  316.            MOVE.W    #$4000,A0            .  Test loca. = $4000.
  317. *------------------------------------------------------------------------------
  318. * CAUTION:  In the above "MOVE.W #$XXXX,A0" do not use an address with the
  319. *           sign bit set, e.g., $8000, because sign extension will cause a
  320. *           BUS ERROR below and crash the system!
  321. *------------------------------------------------------------------------------
  322.            MOVE.L    D1,(A0)
  323.            T_DELAY
  324.            IF.L  D1 <EQ> (A0)  THEN.S     .  If test loca. is good, then
  325.               MOVE.L    D2,(A0)
  326.               T_DELAY
  327.               IF.L  D2 <EQ> (A0)  THEN.S  .    If inverse is good, then
  328.                  MOVEQ.L   #OLD_BCC,D0    .      Got RAM, so must be old BCC.
  329.               ENDI
  330.            ENDI
  331.         ENDI
  332.  
  333.         CMP.B     #OLD_BCC,D0
  334.         BNE.S     BCC_NEW                 Branch if old BCC not found!
  335.  
  336. * Here for old BCC and old Platform board (see Rev. 1 schematics for each):
  337. *
  338. *  U1/U3 = 120 nsec RAM w/fast termination
  339. *  U2/U4 = ROM, but laid out wrong, so can only be used as 120 nsec RAM!
  340. *
  341. *   CSBOOT = BCC U4       332Bug EPROM
  342. *   CS0    = BCC U3       write enable for MSB=UPPER=EVEN ram
  343. *   CS1    = BCC U2       write enable for LSB=LOWER=ODD  ram
  344. *   CS2    = PFB U1/U3    read  enable for MSB/LSB=BOTH   rams
  345. *   CS3    = PFB U1       write enable for LSB=LOWER=ODD  ram
  346. *   CS4    = PFB U4       read  enable for MSB=UPPER=EVEN rom
  347. *   CS5    = PFB U2       read  enable for LSB=LOWER=ODD  rom
  348. *   CS6    = PFB U5       chip  enable for MC68881/882
  349. *   CS7    = <unused>
  350. *   CS8    = PFB          ABORT pushbutton autovector
  351. *   CS9    = <unused>
  352. *   CS10   = PFB U3       write enable for MSB=UPPER=EVEN ram
  353. *                         . cut/jump U3-27 from CS4 to CS10 required!
  354. *
  355. * Set up other CHIP SELECT ports (CS0,CS1,CSBOOT already done):
  356. *
  357. BCC_OLD LEA       ((.CSBAR2).L,PC),A0         Point to old CS2 entry.
  358.         LEA       CSBAR2,A1               Point to corresponding SIM reg.
  359.         MOVEQ.L   #(10-2+1)-1,D0          Set count to do CS2-CS10.
  360. *                                         .  ("-1" for DBRA loop below!)
  361.         BRA.S     CS_COM                  Go to common init routine!
  362.  
  363.  
  364. * Here for new BCC and new Platform board (see Rev. 2 schematics for each):
  365. *
  366. *  U1/U3 = 120 nsec RAM w/fast termination
  367. *  U2/U4 = 250 nsec ROM (or jumper selectable as RAM)
  368. *
  369. *   CSBOOT = BCC U4       332Bug EPROM
  370. *   CS0    = BCC U3       write enable for MSB=UPPER=EVEN ram
  371. *   CS1    = BCC U2       write enable for LSB=LOWER=ODD  ram
  372. *   CS2    = BCC U3/U2    read  enable for MSB/LSB=BOTH   rams
  373. *   CS3    = <unused>
  374. *   CS4    = PFB          ABORT pushbutton autovector
  375. *   CS5    = PFB U5       chip  enable for MC68881/882
  376. *                         . cut/jump U5-J3 from CS2 to CS5 required!
  377. *   CS6    = PFB U2       read  enable for LSB=LOWER=ODD  rom
  378. *   CS7    = PFB U4       read  enable for MSB=UPPER=EVEN rom
  379. *   CS8    = PFB U1/U3    read  enable for MSB/LSB=BOTH   rams
  380. *   CS9    = PFB U1       write enable for LSB=LOWER=ODD  ram
  381. *   CS10   = PFB U3       write enable for MSB=UPPER=EVEN ram
  382. *
  383. * Set up all CHIP SELECT ports (CSBOOT already done):
  384. *
  385. BCC_NEW LEA       ((CSBAR0$).L,PC),A0     Point to new CS0 entry.
  386.         LEA       CSBAR0,A1               Point to corresponding SIM reg.
  387.         MOVEQ.L   #(10-0+1)-1,D0          Set count to do CS0-CS10.
  388. *                                         .  ("-1" for DBRA loop below!)
  389.  
  390. * Common CHIP SELECTS initialization routine:
  391. *   A0.L = chip select configuration table entry (base addr)
  392. *   A1.L = corresponding SIM register
  393. *   D0.W = number of chip selects -1 to be initialized
  394. *
  395. CS_COM  MOVE.L    (A0)+,(A1)+   Init. SIM base addr + option register.
  396.         DBRA      D0,CS_COM     Continue until all regs init'ed.
  397.  
  398.         BRA.L     PWR_TTL       Return to Power On Branch Vector
  399.         END
  400.